package com.zhongketech.sunflower.activity;

import java.util.ArrayList;
import java.util.List;

import com.zhongketech.sunflower.R;
import com.zhongketech.sunflower.transport.Action;
import com.zhongketech.sunflower.transport.LogUtil;
import com.zhongketech.sunflower.utils.Root;

import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;

public class AppKillActivity extends Activity {
	LinearLayout linear = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.setContentView(R.layout.app_kill_dialog);

		this.linear = (LinearLayout) super.findViewById(R.id.linear);
		this.linear.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		LogUtil.i("ZK", "keyCode:"+keyCode);
		if(KeyEvent.KEYCODE_BACK == keyCode)
		{
			new Thread(new Runnable() {
				public void run() {
					Looper.prepare();
					List<String> cmdList = new ArrayList<String>();
					cmdList.add("input keyevent 3");
					try {
						Root.doCmds(cmdList);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				}
			}).start();
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		finish();
	}

	/**
	 * 触摸上面的LinearLayout之外的地方都会关闭本Activity
	 */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		this.finish();// 结束本Activity
		return super.onTouchEvent(event);
	}

}
